package com.babyqiao.wallpaper.manager.controller;


import com.babyqiao.wallpaper.common.UnifyResult;
import com.babyqiao.wallpaper.manager.entity.WallpaperAlbumTopRel;
import com.babyqiao.wallpaper.manager.entity.vo.AlbumAndTopVO;
import com.babyqiao.wallpaper.manager.service.IWallpaperAlbumTopRelService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import reactor.core.publisher.UnicastProcessor;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author QLZ
 * @since 2021-02-23
 */
@Api(tags = "专辑置顶管理接口")
@RestController
@RequestMapping("/api/cms/album/top")
public class AlbumTopRelController {
    @Autowired
    private IWallpaperAlbumTopRelService albumTopRelService;

    @PostMapping("top")
    @ApiOperation(value = "添加最热或人气置顶",httpMethod = "POST")
    public UnifyResult addTop(@ApiParam(name = "wallpaperAlbumTopRel",value = "专辑和置顶关系实体",required = true) @RequestBody WallpaperAlbumTopRel wallpaperAlbumTopRel){
        boolean save = albumTopRelService.save(wallpaperAlbumTopRel);
        return save?UnifyResult.success():UnifyResult.error();
    }
    @DeleteMapping("top/{id}")
    @ApiOperation(value = "删除置顶",httpMethod = "DELETE")
    public UnifyResult removeHot(@PathVariable String id){
        boolean b = albumTopRelService.removeById(id);
        return b?UnifyResult.success():UnifyResult.error();

    }
    @PutMapping("top")
    @ApiOperation(value="修改最热置顶",httpMethod = "PUT")
    public UnifyResult updateHot(@RequestBody WallpaperAlbumTopRel wallpaperAlbumTopRel){
        boolean b = albumTopRelService.updateById(wallpaperAlbumTopRel);
        return b?UnifyResult.success():UnifyResult.error();
    }

    /**
     * 获取所有热度置顶的方法
     */
    @GetMapping("/hots")
    @ApiOperation(value = "查找所有专辑最热置顶", httpMethod = "GET")
    public UnifyResult findAllByHot(){
        List<AlbumAndTopVO> albumAndTopVOList =albumTopRelService.getAllByHotService();
        return UnifyResult.success().data("result",albumAndTopVOList);

    }

    /**
     * 获取所有人气置顶的方法
     */
    @GetMapping("/likes")
    @ApiOperation(value = "查找所有专辑人气置顶", httpMethod = "GET")
    public UnifyResult findAllBylike(){
        List<AlbumAndTopVO> albumAndTopVOList =albumTopRelService.getAllByLikeService();
        return UnifyResult.success().data("result",albumAndTopVOList);

    }




}
